#ifndef TTEXT_LIB_H
#define TTEXT_LIB_H

#define SQL_TEXT Latin_Text
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include "sqltypes_td.h"

#undef TTEXT_OPTION_TRACE

#if defined(_WIN32)
#pragma warning(disable: 4100 4702 4996)
#endif

typedef int BOOLEAN;

#define TRUE   -1
#define FALSE   0

#define TTEXT_set_error_message(A, B) \
  *resultIsNull = FALSE; \
  strncpy((char *)sqlstate, (const char *)(A), 5); \
  strncpy((char *)error_message, (const char*)(B), 256)

#if defined(TTEXT_OPTION_TRACE)

/***************************************************
CREATE GLOBAL TEMPORARY TRACE TABLE SYSLIB.UDF_TRC (
  VPROC_ID BYTE(2)
, SEQ_NBR  INTEGER
, MSG_TXT  VARCHAR(1000)
) ON COMMIT PRESERVE ROWS;

SET SESSION FUNCTION TRACE USING 'parameter' FOR TRACE TABLE SYSLIB.UDF_TRC;

SELECT * FROM SYSLIB.UDF_TRC ORDER BY VPROC_ID, SEQ_NBR;

DELETE SYSLIB.UDF_TRC ALL;
***************************************************/

static void TTEXT_trace(char *format, ...)
{
  static char  message[1000];
         void *argv[1];
      va_list  args;

  va_start(args, format);

  _vsnprintf(message, 999, format, args);

  argv[0] = (void *)message;

  FNC_Trace_Write(1, argv);

  va_end(args);

  return;
}

#else

static void TTEXT_trace(char *format, ...) { }

#endif

#endif TTEXT_LIB_H
